#include <device.h>
#include <errno.h>
#include <string.h>

#ifdef __TOP_HALF__

struct device *device_lookup_by_id(unsigned int id, int index)
{
	struct device *dev;

	for_each_device(dev) {
		if ((dev->id == id) && (dev->index == index)) 
			return dev;
	}

	return ERR_PTR(-ENODEV);
}

#else

struct device *device_lookup_by_name(const unsigned char *name, int index)
{
	struct device *dev;

	for_each_device(dev) {
		if ((strcmp(dev->name, name) == 0) && (dev->index == index)) {
			return dev;
		}
	}

	return ERR_PTR(-ENODEV);
}

struct device *device_lookup(unsigned int major, unsigned int minor)
{
	struct device *dev;

	for_each_device(dev) {
		if ((dev->major == major) && (dev->minor == minor)) {
			return dev;
		}
	}

	return ERR_PTR(-ENODEV);
}

int device_open(struct device *dev, unsigned int flags)
{	
	struct driver = dev->driver;
	
	dev->flags = flags;
	driver->dev_ops->open(dev);	
}

#endif

/* test */
